#!/bin/bash
source tools/getenv.sh

function myDevStatus() {
  num=$(getGrepPidFileNum)
  if [[ "$num" -eq 0 ]]; then
    echo -e "${GREEN}进程不存在...$RESET"
  else
    echo  -e "${GREEN}进程存在，进程列表如下：$RESET"
    # shellcheck disable=SC2009
    ps aux | grep -v ".log" | grep -v tail | grep -v grep | grep --color "$APP_BIN_NAME"
  fi
}

function myStatus() {
  echo "================================================================================================================="
  echo ""
  echo -e "$CYAN 查看${BOLDMAGENTA} stock$CYAN 服务进程是否存在...$RESET"
  num=$(getServerBinAllPathNum)
  if [[ $num -eq 0 ]]; then
    echo -e "${BOLODRED}进程不存在$RESET"
  else
    echo -e "$BOLODGREEN 进程存在 $RESET"
    psServerBinAllPath
  fi
}

if [[ "$env" == "dev" ]]; then
  myDevStatus
elif [[ "$env" == "test" || "$env" == "prod" ]]; then
  myStatus
  if [[ "$damonMode" == "supervisor" ]]; then
    mySupervisorStatus
  elif [[ "$damonMode" == "systemd" ]]; then
    mySystemdStatus
  fi
fi
